<?php

namespace Modules\Product\Entities;

use Modules\Core\Entities\BaseEntity as Model;
use ThrowException;

class ProductExt extends Model
{
    protected $guarded = [];
    protected $table = 'product_exts';

    static public $resourceName = '属性';

    protected $casts = [
        //'tags' => 'array',
        'images' => 'array',
        'videos' => 'array',
        'header_attrs' => 'array',
        'normal_attrs' => 'array',
        'sku_attrs' => 'array',
        'page' => 'array',
    ];

    public function product()
    {
        return $this->belongsTo('\Modules\Product\Entities\Product', 'product_id');
    }

    public function setAttrsAttribute($value)
    {
        if (is_array($value))
            $value = json_encode($value,  JSON_UNESCAPED_UNICODE) ;
        $this->attributes['all_attrs'] = $value;
    }

    public function setSkuAttrsAttribute($value)
    {
        if (is_array($value))
        	$value = json_encode($value,  JSON_UNESCAPED_UNICODE) ;
        $this->attributes['sku_attrs'] = $value;
    }

    public function setHeaderAttrsAttribute($value)
    {
        if (is_array($value))
        	$value = json_encode($value,  JSON_UNESCAPED_UNICODE) ;
        $this->attributes['header_attrs'] = $value;
    }
}
